package com.remainder.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import com.remainder.common.core.domain.R;
import com.remainder.system.api.RemoteConfigService;

/**
 * @Author wanggang
 * @Description 系统配置项查询回调函数
 * @Date 2022/10/12
 * @Version 1.0
 **/
@Component
public class RemoteConfigFallbackFactory implements FallbackFactory<RemoteConfigService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteConfigFallbackFactory.class);

    @Override
    public RemoteConfigService create(Throwable throwable) {
        log.error("系统服务调用失败:{}", throwable.getMessage());

        return new RemoteConfigService() {
            /**
             * 根据key值查询系统配置信息
             *
             * @param configKey
             *            系统配置key
             * @return R<String>
             */
            @GetMapping("/config/configInfoKey/{configKey}")
            @Override
            public R<String> configInfoKey(@PathVariable("configKey") String configKey) {
                log.error("系统获取服务:{}", throwable.getMessage());
                return R.fail("查询系统配置项失败:" + throwable.getMessage());
            }

            /**
             * 根据字典类型查询字典数据信息
             *
             * @param dictType
             *            字典类型
             * @return 结果
             */
            @Override
            public R<?> getDictType(String dictType) {
                log.error("系统获取字典:{}", throwable.getMessage());
                return R.fail("查询系统获取字典失败:" + throwable.getMessage());
            }

            /**
             * 执行日切
             *
             * @return 结果
             */
            @Override
            public R<?> updateDailyDate() {
                log.error("执行日切:{}", throwable.getMessage());
                return R.fail("执行日切失败:" + throwable.getMessage());
            }
        };
    }
}
